﻿using System;
using System.Windows.Data;
using System.Windows.Media;

namespace XamlaApp.Converters
{
    public class ImageStretchToString : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return 0;

            var tr = (Stretch)value;
            switch (tr)
            {
                case Stretch.None:
                    return 0;
                case Stretch.Fill:
                    return 1;
                case Stretch.Uniform:
                    return 2;
                case Stretch.UniformToFill:
                    return 3;
            }
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return Stretch.None;

            var c = (int) value;
            switch (c)
            {
                case 0:
                    return Stretch.None;
                case 1:
                    return Stretch.Fill;
                case 2:
                    return Stretch.Uniform;
                case 3:
                    return Stretch.UniformToFill;
            }

            return Stretch.None;
        }

        #endregion
    }
}
